var pluck = require('arr-pluck');


var arr = [{ 'a': 'b', 'c': 'd' }, { 'a': 'f', 'c': 'e' }];
console.log(pluck(arr, 'a'))
console.log(pluck(arr, 'abb'))
console.log(pluck('arr', 'abb'))
console.log(pluck(333, 'abb'))

console.log('-----------------------\n')

console.log(arrayPluck(arr, 'a'))
console.log(arrayPluck(arr, 'abb'))
console.log(arrayPluck('arr', 'abb'))
console.log(arrayPluck(333, 'abb'))



function arrayPluck(arr, property) {
	if(arr == null) return []
	var result = new Array(arr.length)

	var validatePropertyExists = false 

	var one 
	for (var i = 0; i < arr.length; i++) {
		one = arr[i]
		if(validatePropertyExists && one.hasOwnProperty(property)) {
			result[i] = one[property]
		} else {
			result[i] = one[property]
		}
	}
	return result
}



/**
 * 提取数组的某一列
 * @param  {[type]} arr    [description]
 * @param  {[type]} property [description]
 * @return {[type]}        [description]
 */
function arrayPluckV2(arr, property) {
	var result = []
	var validatePropertyExists = false 

	var one 
	for (var i = 0; i < arr.length; i++) {
		one = arr[i]
		if(validatePropertyExists && one.hasOwnProperty(property)) {
			result.push(one[property])
		} else {
			result.push(one[property])
		}
	}
	return result
}



